import {search} from '@/services/api/article';
import {convertPageData} from '@/utils/request';
import React, {useRef} from 'react';

import {ActionType, PageContainer, ProColumns, ProTable} from '@ant-design/pro-components';

export default () => {
  const refAction = useRef<ActionType>(null);
  const columns: ProColumns<API.LuceneResultBookVO>[] = [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 50,
      search: false,
    },
    {
      title: '文章标题',
      dataIndex: 'title',
      width: 100,
      search: false,
    },
    {
      title: '作者',
      dataIndex: 'author',
      width: 100,
      search: false,
    },
    {
      title: '得分',
      dataIndex: 'score',
      width: 100,
      search: false,
    },
    {
      title: '内容',
      dataIndex: 'content',
      render: (_: any, record) => {
        const text = record?.content?.join('...') || '';
        return <div dangerouslySetInnerHTML={{__html: text}}></div>
      }
    },
  ];

  return (
    <PageContainer>
      <ProTable<API.LuceneResultBookVO>
        // 检索结果返回
        actionRef={refAction}
        manualRequest={true}
        request={async (params = {}) => {
          return convertPageData(await search(params));
        }}
        // 分条目展示
        columns={columns}
      />
    </PageContainer>
  );
};
